package com.example._2025_03_29;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/header")
public class HeaderController {
    /*
        获取 header
     */
    @RequestMapping("/getHeader")
    public String getHeader(HttpServletRequest request) {
        String userAgent = request.getHeader("User-Agent");
        System.out.println("userAgent: " + userAgent);
        return "userAgent: " + userAgent;
    }

    /*
        通过注解获取 header
        @RequestHeader
     */
    @RequestMapping("/getHeader2")
    public String getHeader2(@RequestHeader("User-Agent") String userAgent) {
        System.out.println("userAgent: " + userAgent);
        return "userAgent: " + userAgent;
    }
}
